package org.springblade.modules.auth.utils;

import org.springblade.modules.auth.bean.RsLicense;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class RsLicenseUtils {
	public static RsLicense readLicenseFile(String filePath) throws IOException {
		BufferedReader reader = new BufferedReader(new FileReader(filePath));
		RsLicense license = new RsLicense();
		String line = null;
		while ((line = reader.readLine()) != null) {
			String[] parts = line.split("=");
			if (parts.length == 2) {
				String key = parts[0];
				String value = parts[1];
				switch (key) {
					case "SN":
						license.setSN(value);
						break;
					case "Modules":
						license.setModules(value);
						break;
					case "Users":
						license.setUsers(Integer.parseInt(value));
						break;
					case "Licensee":
						license.setLicensee(value);
						break;
					case "ExpireDate":
						license.setExpireDate(value);
						break;
					case "LicenseDate":
						license.setLicenseDate(value);
						break;
					case "Sign":
						license.setSign(value);
						break;
					default:
						// 忽略未知键
						break;
				}
			}
		}
		reader.close();
		return license;
	}
}
